package com.example.task1.ui.AllService.word;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.WordTheBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class WordTheListAdapter extends BaseAdapter<WordTheBean.RowsDTO> {

    private List<WordTheBean.RowsDTO> data = new ArrayList<>();
    private Context context;
    private TextView tvName;
    private TextView tvContent;

    public WordTheListAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<WordTheBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.wordthelist;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<WordTheBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, WordTheBean.RowsDTO date) {
        tvName.setText(date.getCompanyName());
        tvContent.setText(date.getIntroductory());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context,WordTheDetailActivity.class,date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private void initView(View itemView) {
        tvName = (TextView) itemView.findViewById(R.id.tv_name);
        tvContent = (TextView) itemView.findViewById(R.id.tv_content);
    }
}
